package com.sbj.dto.utils;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ByteUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTPayload;
import cn.hutool.jwt.JWTUtil;
import cn.hutool.jwt.signers.JWTSigner;
import cn.hutool.jwt.signers.JWTSignerUtil;
import com.zmh.framework.exception.ResultException;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/19 21:23
 */
@Slf4j
public class JWTUtils {




    public static String sign(Map<String, Object> map) {
        return JWTUtil.createToken(map, ByteUtil.intToBytes(4));
    }


    public static Map<String,Object> parseToken(String sign){
        boolean verify = JWTUtil.verify(sign, ByteUtil.intToBytes(4));
        if(!verify){
            log.error("商品参数错误.........");
            throw new ResultException("非法参数");
        }
        JWT jwt = JWTUtil.parseToken(sign);
        return Convert.toMap(String.class, Object.class, jwt.getPayload().getClaimsJson());
    }

    public static void main(String[] args) {
        System.out.println(orderAmount(new BigDecimal(3000),30));
     }

    public static BigDecimal orderAmount(BigDecimal original,Integer ratio ){
        BigDecimal div = NumberUtil.div(new BigDecimal(ratio), 100);
        return NumberUtil.add(original, NumberUtil.mul(original,div));
    }




}
